// pages/home/index.js
import { getFirstFolder } from "../../utils/request/folder/index.js"
console.log(getFirstFolder)
Page({
  data: {
    folderList:[],
  },
  /**
   * 生命周期函数--监听页面加载
   */
  async onLoad(options) {
    let session  = wx.getStorageSync('session')
    
    try{
    
      let res = await getFirstFolder({},session)
     
      console.log(res.data)
      if(res.code === 0){
        this.setData({
          folderList:res.data
        })
      }
      console.log(res)
      if(res.code == 40100){
        wx.removeStorage({
          key: 'userInfo',
          success() {
            console.log("删除成功")
            console.log(wx.getStorageSync('session'))
          }
        })
        wx.removeStorage({
          key: 'session',
          success() {
            console.log("删除成功")
          }
        })
        wx.redirectTo({
          url: '../login/index',
          fail(err) {
            console.log(err)
          }
        })
      }
    }catch(err){
      console.log(err)
      wx.showToast({
        title: '获取失败',
        icon:"none"
      })
    }
   
    
  },
  /**
   * 仅负责跳转页面
   */
  handleClick(e){
    
    let index = e.currentTarget.dataset.id
    let id = this.data.folderList[index].id
    let typeName = this.data.folderList[index].typeName
    let arr = []
    arr.push(typeName)
    console.log(id,arr)
    wx.navigateTo({
      url: `../index/index?id=${id}&typeName=${typeName}&typeArr=${arr}&go=true`,
    })
  }
 
})